#ifndef CONTENTSEARCHER_H
#define CONTENTSEARCHER_H

#include <QtGui/QMainWindow>

#include "ui_contentsearcher.h"
#include "ui_contentsearcher_dialog_searching.h"
#include "ui_contentsearcher_dialog_option.h"
#include "ui_contentsearcher_dialog_replace.h"
#include "htmltextdelegate.h"
#include "operationhandler.h"
#include "messagedeliver.h"


class ContentSearcher : public QMainWindow
{
	Q_OBJECT

public:
	ContentSearcher(QWidget *parent = 0, Qt::WFlags flags = 0);
	~ContentSearcher();

signals:
	void stopAll();	// Emit when close main window and background thread doing searching or replacing. Interrupt and recycle parallel thread.

private slots:
	void initialProgressRange(const int maximum);
	void setSearchPath();
	void setTxtEditorPath();	// Set note pad application path.
	void setBinEditorPath();	// Unsupported so far.
	void doSearch();
	void doReplace();

	void showRightClickMenu(const QModelIndex& index);

	/* Right click context menu operation */
	void notePadOpen(const QModelIndex& index);	// Use notepad to open the selected file, use in double click a result item.
	void notePadOpen();	// Use notepad to open the selected file, use in right click menu.
	void extAppOpen();	// Use default external application open selected item.
	void copyToClipboard();	// Copy the selected item to clip board.
	void printSelectedItem();	// Print the search result.
	void expToXml();	// Export the search result to a XML file.

	/* Control Searcher to replace or skip a match item */
	void skipThis();	// Get user's feedback, skip a replace.
	void replaceThis();	// Get user's feedback, confirm a replace.

	/* Signal from MessageDeliver */
	void updateResultLabel(const QString &string);	//  To update result label which is above of result tree view.
	void updateProgressBar(const int i, const QString &string);
	void updateCompletedItem(QStandardItem *item);	// To append the processed item to [member mResultModel].
	void updateFailedItem(const QString s);	// To report the failed item.
	void searchReplaceCompleted(QString string = 0);	// Searcher completed or interrupted will trigger this.
	void otherOperationCompleted();		// Deal with print and export to XML finish.
	void popUpWarning(const QString &title, const QString &content);
	void popUpQuestion(const QString &title, const QString &content);
	void popUpReplace(QStandardItemModel *model);

private:
	virtual void closeEvent(QCloseEvent * event);

	Ui::dialog_main ui_main;
	Ui::dialog_option ui_dialog_option;
	Ui::dialog_replace ui_dialog_replace;

	QDialog *m_pDialogOption;
	QDialog *m_pDialogReplace;	
	QStandardItemModel *m_pResultModel;	// Search or replace result item model for result tree view.

	QMenu *m_pMenuRightClick;		// Right click context menu.
	QAction *m_pActionExtAppOpen;
	QAction *m_pActionPrint;
	QAction *m_pActionCopy;
	QAction *m_pActionNotePadOpen;
	QAction *m_pActionExpXml;

	QProgressBar *m_pProgressBar;
	QLabel *m_pLabelProcess;
	QLabel *m_pLabelStatus;
	QPushButton *m_pPushButtonStop;

	QModelIndex m_pSelectedModelIndex;	// For marking the right click selected item.
	HtmlTextDelegate *m_pHTMLTextDelegate;	// For highlight display match item in result tree view.

	OperationHandler *m_pOperationHandler;
	MessageDeliver *m_pMessageDeliver;

	int m_nProgressCnt;	// For progress bar display.
	int m_nTotalMatch;	// Total matches in searching files.
	int m_nTotalSearchFiles;	// Total searched files.
	int m_nTotalMatchInFiles;  // Total files number after filtering.
	int m_nPendingFiles;	 // Total files number pending process.
};




#endif // CONTENTSEARCHER_H
